/*
 * SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

use std::fs::File;
use std::io::Write;
use std::process::Command;
use tempfile::tempdir;

#[test]
fn test_utzipcloak() {
    let dir = tempdir().unwrap();
    let zip_path = dir.path().join("cloak.zip");
    let file_path = dir.path().join("secret.txt");
    let mut file = File::create(&file_path).unwrap();
    writeln!(file, "secret data").unwrap();

    // 创建zip
    let status = Command::new("./target/debug/utzip")
        .arg(&zip_path)
        .arg(&file_path)
        .status()
        .unwrap();
    assert!(status.success());

    // 加密
    let status = Command::new("./target/debug/utzipcloak")
        .env("UTZIP_TEST_PASSWORD", "123456")
        .arg(&zip_path)
        .status()
        .unwrap();
    assert!(status.success());

    // 解密
    let status = Command::new("./target/debug/utzipcloak")
        .env("UTZIP_TEST_PASSWORD", "123456")
        .arg(&zip_path)
        .arg("--decrypt")
        .status()
        .unwrap();
    assert!(status.success());
}
